﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KP_CommonLibrary.KP_DataAccess;
using KP_CommonLibrary.KP_ObjectReferences;
using System.Data;
using Microsoft.ApplicationBlocks.Data;

namespace KEEPER_BRR_13dotNET.DataAccess
{
    public class DAL_KPDmNganh : KP_DALListBase
    {
        public DAL_KPDmNganh()
            : base("tblDmNganh")
        {
        }
        public override System.Data.DataTable Select()
        {
            return SqlHelper.ExecuteDataTable(KP_OCnnSql.Cnn_String, CommandType.Text, "Select T1.*,Ten_Nhom  from tblDmNganh T1 Inner join tblDmNhomNganh T2 ON T2.Ma_Nhom=T1.Ma_Nhom");

            //return base.Select();
        }
        public  System.Data.DataTable SelectAll()
        {
            DataTable tblData= SqlHelper.ExecuteDataTable(KP_OCnnSql.Cnn_String,"kp_DmNganhSelectAll",new object[]{});
            tblData.TableName = TableName;
            return tblData;
        }
        public System.Data.DataTable SelectByHoSoSttRec(string hoSoSttRec)
        {
            DataTable tblData= SqlHelper.ExecuteDataTable(KP_OCnnSql.Cnn_String, "kp_DmNganhSelectByHoSoSttRec", new object[] { hoSoSttRec });
            tblData.TableName = "tblNganhHSo";
            return tblData;
        }
        public void Insert(DataRow row, DataTable tblGiayTo)
        {
            DAL_KPGiayToKemTheo dalGiayTo = new DAL_KPGiayToKemTheo();
            try
            {
                OpenConnection();
                BeginTransaction();
                Insert(Transaction, row);
                if (tblGiayTo != null)
                    dalGiayTo.Update(Transaction, tblGiayTo);
                Transaction.Commit();
                Transaction = null;
            }
            catch (Exception e)
            {
                if (Transaction != null)
                    Transaction.Rollback();
                Transaction = null;
                throw e;
            }
            finally
            {
                CloseConnection();

            }
        }
        public void Update(DataRow row, DataTable tblGiayTo)
        {
            DAL_KPGiayToKemTheo dalGiayTo = new DAL_KPGiayToKemTheo();
            try
            {
                OpenConnection();
                BeginTransaction();
                Update(Transaction, row);
                if (tblGiayTo != null)
                    dalGiayTo.Update(Transaction, tblGiayTo);
                Transaction.Commit();
                Transaction = null;
            }
            catch (Exception e)
            {
                if (Transaction != null)
                    Transaction.Rollback();
                Transaction = null;
                throw e;
            }
            finally
            {
                CloseConnection();

            }
        }


    }
}
